#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V;
struct carOutRange{
    int s,e;
}range[100001];
struct scaner{
    int p;
    vector<pair<int,int> > scaned;
}scan[100001];
int d[100001],v[100001],a[100001];
int ans1,ans2;
bool cmp(carOutRange a,carOutRange b){
    return a.s<b.s?1:(a.s==b.s?a.e<b.e:0);
}bool cmp2(scaner a,scaner b){
    return a.p<b.p;
}int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    while(T--){
        cin >> n >> m >> L >> V;
        ans1=0;
        for(int i=1;i<=n;i++){
            cin >> d[i] >> v[i] >> a[i];
            if(a[i]>0){
                if(v[i]>V){
                    range[i].s=d[i];
                    range[i].e=L;
                    ans1++;
                }else{
                    range[i].s=d[i]+(V*V-v[i]*v[i])/(2*a[i])+1;
                    range[i].e=L;
                    ans1++;
                }
            }else if(a[i]==0){
                if(v[i]>V){
                    range[i].s=d[i];
                    range[i].e=L;
                    ans1++;
                }else{
                    range[i].s=0x3f3f3f3f;
                    range[i].e=0x3f3f3f3f;
                }
            }else{
                if(v[i]>V){
                    range[i].s=d[i];
                    range[i].e=d[i]+(V*V-v[i]*v[i])/(2*a[i])-((V*V-v[i]*v[i])%(2*a[i])?0:1);
                    ans1++;
                }else{
                    range[i].s=0x3f3f3f3f;
                    range[i].e=0x3f3f3f3f;
                }
            }
        }sort(range+1,range+1+n,cmp);
        for(int i=1;i<=m;i++){
            cin >> scan[i].p;
        }sort(scan+1,scan+1+m,cmp2);
        int l=1,r=1;
        ans2=0;
        if(range[r].e<scan[1].p)ans1--;
        for(int i=1;i<=m;i++){
            scan[i].scaned.clear();
            if(range[l].s>scan[i].p)continue;
            while(l+1<=n&&range[l+1].e<scan[i].p)l++;
            int s=l;
            while(r+1<=n&&range[r+1].s<scan[i].p){
                r++;
                if(r>=l&&range[r].e<scan[i].p){
                    pair<int,int> p;
                    p.first=s;
                    p.second=r-1;
                    scan[i].scaned.push_back(p);
                    s=r+1;
                    ans1--;
                }
            }if(l>r)continue;
            pair<int,int> p;
            p.first=s;
            p.second=r-(range[r].e<scan[i].p);
            scan[i].scaned.push_back(p);
            bool f=0;
            if(scan[i-1].scaned.size()==scan[i].scaned.size()){
                for(int ii=0;ii<scan[i-1].scaned.size();ii++){
                    if(!(scan[i-1].scaned[ii].first==scan[i].scaned[ii].first&&scan[i-1].scaned[ii].second==scan[i].scaned[ii].second)){
                        f=1;
                        break;
                    }
                }
            }if(f){
                int j=0,k=0;
                while(j<scan[i-1].scaned.size()&&k<scan[i].scaned.size()){
                    if(scan[i-1].scaned[j].first<=scan[i].scaned[k].first&&scan[i].scaned[j].second<=scan[i-1].scaned[k].second)k++;
                    else j++;
                }if(k==scan[i].scaned.size()-1)ans2++;
                else{
                    j=0;k=0;
                    while(k<scan[i-1].scaned.size()&&j<scan[i].scaned.size()){
                        if(scan[i].scaned[j].first<=scan[i-1].scaned[k].first&&scan[i-1].scaned[k].second<=scan[i].scaned[k].second)j++;
                        else k++;
                    }if(k==scan[i-1].scaned.size()-1)ans2++;
                }
            }else{
                ans2++;
            }
        }cout << ans1 << " " << ans2 << "\n";
    }
    return 0;
}